import java.util.ArrayList;
import java.util.LinkedList;

public class Heuristic {

	private Kattio kattio;

	private ArrayList<LinkedList<Integer>> roles;
	private ArrayList<LinkedList<Integer>> scenes;
	private int nroles;
	private int nscenes;
	private int nactors;
	private int nactingactors;
	private int diva1;
	private int diva2;
	private ArrayList<LinkedList<Integer>> actingactors;
	private ArrayList<Integer> superactors;

	public Heuristic() {
		kattio = new Kattio(System.in, System.out);
		roles = new ArrayList<LinkedList<Integer>>();
		scenes = new ArrayList<LinkedList<Integer>>();
		actingactors = new ArrayList<LinkedList<Integer>>();
		superactors = new ArrayList<Integer>();
		stufftodo();
	}

	private void stufftodo() {
		read();
		// testprint();
		crew();
		printsolution();
	}

	private void crew() {
		boolean divas = finddivas();
		if (divas) {
			actingactors.add(new LinkedList<Integer>());
			actingactors.add(new LinkedList<Integer>());
			actingactors.get(0).add(1);
			actingactors.get(0).add(diva1);
			actingactors.get(1).add(2);
			actingactors.get(1).add(diva2);
		}
		addsuperactors();
	}

	private void addsuperactors() {
		for (int i = 1; i <= nroles; i++) {
			if (i != diva1 && i != diva2) {
				superactors.add(i);
			}
		}
	}

	private boolean finddivas() {
		for (int i = 1; i < nroles; i++) {
			for (int k = i + 1; k <= nroles; k++) {
				if (!checkifinsamescene(i, k)) {
					diva1 = i;
					diva2 = k;
					boolean d1 = checkifroleisinanyscene(diva1);
					boolean d2 = checkifroleisinanyscene(diva2);
					if (d1 && d2) {
						return true;
					}
				}
			}
		}
		return false;
	}

	private boolean checkifroleisinanyscene(int role) {
		for (LinkedList<Integer> list : scenes) {
			for (int s : list) {
				if (s == role) {
					return true;
				}
			}
		}
		return false;
	}

	private boolean checkifinsamescene(int act1, int act2) {
		boolean first = false;
		boolean second = false;
		for (LinkedList<Integer> list : scenes) {
			for (int s : list) {
				if (s == act1) {
					first = true;
				} else if (s == act2) {
					second = true;
				}
			}
			if (first && second) {
				return true;
			} else {
				first = false;
				second = false;
			}
		}
		return false;
	}

	private void printsolution() {
		nactingactors = actingactors.size() + superactors.size();
		pl("" + nactingactors);
		LinkedList<Integer> list;
		for (int i = 0; i < actingactors.size(); i++) {
			list = actingactors.get(i);
			p(list.get(0) + " ");
			p((list.size() - 1) + " ");
			if (list.size() > 1) {
				for (int k = 1; k < list.size(); k++) {
					p(list.get(k) + " ");
				}
			}
			pl("");
		}
		for (int i = 0; i < superactors.size(); i++) {
			pl((nactors + 1 + i) + " " + 1 + " " + superactors.get(i));
		}
	}

	private void read() {
		nroles = kattio.getInt();
		nscenes = kattio.getInt();
		nactors = kattio.getInt();
		roles = new ArrayList<LinkedList<Integer>>(nroles + 1);
		roles.add(new LinkedList<Integer>());
		scenes = new ArrayList<LinkedList<Integer>>(nscenes + 1);
		scenes.add(new LinkedList<Integer>());

		int nplayrole;
		for (int i = 1; i <= nroles; i++) {
			nplayrole = kattio.getInt();
			roles.add(new LinkedList<Integer>());
			for (int k = 1; k <= nplayrole; k++) {
				roles.get(i).add(kattio.getInt());
			}
		}

		int nrolesinscene;
		for (int i = 1; i <= nscenes; i++) {
			nrolesinscene = kattio.getInt();
			scenes.add(new LinkedList<Integer>());
			for (int k = 1; k <= nrolesinscene; k++) {
				scenes.get(i).add(kattio.getInt());
			}

		}
	}

	private void testprint() {
		for (LinkedList<Integer> l : roles) {
			for (int s : l) {
				p(s + " ");
			}
			pl("");
		}
		for (LinkedList<Integer> l : scenes) {
			for (int s : l) {
				p(s + " ");
			}
			pl("");
		}
		pl(".........................");
	}

	private void p(String s) {
		kattio.print(s);
		kattio.flush();
	}

	private void pl(String s) {
		kattio.println(s);
		kattio.flush();
	}

}
